package com.open.capacity.finance.controller;

import com.open.capacity.commons.Result;
import com.open.capacity.finance.entity.SysUsersettingDefault;
import com.open.capacity.finance.service.HomeService;
import com.open.capacity.finance.service.SysUsersettingDefaultService;
import com.open.capacity.model.system.SysUser;
import com.open.capacity.utils.SysUserUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;

/**
 * 首页
 *
 * @author
 * @email
 * @date 2020-06-03 22:56:50
 */
@Slf4j
@RestController
@RequestMapping("homes")
@Api(tags = "首页")
public class HomeController {

    @Autowired
    private HomeService service;

    @Autowired
    private SysUsersettingDefaultService sysUsersettingDefaultService;

    /**
     * 列表
     */
    @RequestMapping("/getData")
    @PreAuthorize("hasAnyAuthority('base_aj:baseaj:list')")
    public Result getData(@RequestParam Map<String, Object> params) throws IOException {
        SysUser loginUser = SysUserUtil.getLoginAppUser();
        SysUsersettingDefault usersettingDefault = sysUsersettingDefaultService.findById(loginUser.getId());
        Result result = service.getData(loginUser, usersettingDefault, params);

        return result;
    }

}
